<?

		$sql['tables']['gt'] = "INNER JOIN geograph_live.gridimage_term AS gt USING (gridimage_id)";

		
		
		$sql['order'] = "term, ".$sql['order'];
		
		
		if (strpos($sql['columns'], ",term") === FALSE) {
			$sql['columns'] .= ",term";
		} 
		function searchbreak(&$c,$start='',$end='') {
			static $last;
			static $count;
			static $hidden;

			if (empty($c)) {//its the last one
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images - <a href=\"".linktoself(array('term'=>$last,'delete'=>array('opt','page')))."\">view all</a>)";
					}
				}
				return;
			}
			
			$term = $c['term'];
			
			if ($term != $last) {
			
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images - <a href=\"".linktoself(array('term'=>$last,'delete'=>array('opt','page')))."\">view all</a>)";
					} else {
						?>
						<script>
						if (document.getElementById('f<? echo $last; ?>')) {
							document.getElementById('f<? echo $last; ?>').style.display = 'none';
						}
						</script>
						<?
					}
				}
				
				print "<h4>".he($term);
					print " <span id=\"f$term\">(<a href=\"".linktoself(array('term'=>$term,'delete'=>array('opt','page')))."\">Show only</a>)</span>";
				print "</h4>";

				
					
				
				print $start;
				$count = 1;
				$hidden =0;
			} else {
				$count++;
				if ($count > 4) {
					$GLOBALS['opt']['has_hidden'] = true;
					$GLOBALS['resultCount']--;
					$hidden++;
					return false;
				}
			}
			
			$last = $term;
			return true; //we dont disable any images...
		}
		
		$opt['opt'] = 'term';
		$opt['title'] = "Images in term order"; 

